<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>hello_react</title>
</head>
<body>
    <!--  准备好一个容器  -->
    <div id="test"></div>

    <!--  引入react核心库  -->
    <script type="text/javascript" src="../../js_base/react.development.js"></script>
    <script type="text/javascript" src="../../js_base/react-dom.development.js"></script>
    <script type="text/javascript" src="../../js_base/babel.min.js"></script>

    <!--  需要使用babel  -->
    <script type="text/babel">
        
        class Weather extends React.Component {
            constructor(props){
                super(props)
                this.state = {isHot:true}
                this.changeWeather = this.changeWeather.bind(this)
            }
            render() {
                console.log(this);
                return <h2 onClick={this.changeWeather}>今天天气很{this.state.isHot ? '炎热' : '凉爽'}</h2>
            }
            // changeWeather方法放在Weather的原型对象上，供实例调用
            // 通过Weather实例调用changeWeather时，changeWeather中的this指向Weather实例
            changeWeather(){
                const isHot = this.state.isHot;
                // 状态state不可以直接通过`this.state.isHot = `进行更改，需要通过内置API修改
                this.setState({isHot:!isHot})
            }
        }

        // 渲染组件到页面
        ReactDOM.render(<Weather/>, document.getElementById('test'));

    </script>

</body>
</html>